<cfparam name="resetFilters" default="false">

<cfset isFiltered = false />

<cfif NOT IsDefined("client.payments.cohorts") or resetFilters>
	<cfset client.payments.cohorts = "All">
<cfelseif IsDefined("filterCohorts")>
	<cfset client.payments.cohorts = filterCohorts>
	<cfif filterCohorts neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.scholarshipTypes") or resetFilters>
	<cfset client.payments.scholarshipTypes = "All">
<cfelseif IsDefined("filterScholarshipTypes")>
	<cfset client.payments.scholarshipTypes = filterScholarshipTypes>
	<cfif filterScholarshipTypes neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.terms") or resetFilters>
	<cfset client.payments.terms = "All">
<cfelseif IsDefined("filterTerms")>
	<cfset client.payments.terms = filterTerms>
	<cfif filterTerms neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.termTypes") or resetFilters>
	<cfset client.payments.termTypes = "All">
<cfelseif IsDefined("filterTermTypes")>
	<cfset client.payments.termTypes = filterTermTypes>
	<cfif filterTermTypes neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.verificationTypes") or resetFilters>
	<cfset client.payments.verificationTypes = "All">
<cfelseif IsDefined("filterVerificationTypes")>
	<cfset client.payments.verificationTypes = filterVerificationTypes>
	<cfif filterVerificationTypes neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.paymentTypes") or resetFilters>
	<cfset client.payments.paymentTypes = "All">
<cfelseif IsDefined("filterPaymentTypes")>
	<cfset client.payments.paymentTypes = filterPaymentTypes>
	<cfif filterPaymentTypes neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.optOut") or resetFilters>
	<cfset client.payments.optOut = "All">
<cfelseif IsDefined("filterOptOut")>
	<cfset client.payments.optOut = filterOptOut>
	<cfif filterOptOut neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.authorized") or resetFilters>
	<cfset client.payments.authorized = "All">
<cfelseif IsDefined("filterAuthorized")>
	<cfset client.payments.authorized = filterAuthorized>
	<cfif filterAuthorized neq "All">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfif NOT IsDefined("client.payments.searchCriteria") or resetFilters>
	<cfset client.payments.searchCriteria = "">
<cfelseif IsDefined("filterSearchCriteria")>
	<cfset client.payments.searchCriteria = filterSearchCriteria>
	<cfif filterSearchCriteria neq "">
		<cfset isFiltered = true />
	</cfif>
</cfif>

<cfinvoke component="#application.paymentGateway#" method="getAllAsQuery" returnvariable="payments">
	<cfinvokeargument name="cohorts" value="#client.orders.cohorts#" />
	<cfinvokeargument name="scholarshipTypes" value="#client.orders.scholarshipTypes#" />
	<cfinvokeargument name="terms" value="#client.orders.terms#" />
	<cfinvokeargument name="termTypes" value="#client.orders.termTypes#" />
	<cfinvokeargument name="verificationTypes" value="#client.orders.verificationTypes#" />
	<cfinvokeargument name="paymentTypes" value="#client.orders.paymentTypes#" />
	<cfinvokeargument name="optOut" value="#client.orders.optOut#" />
	<cfinvokeargument name="authorized" value="#client.orders.authorized#" />
	<cfinvokeargument name="searchCriteria" value="#client.orders.searchCriteria#" />
</cfinvoke>

<cfoutput>

	<cfform name="paymentsForm" id="paymentsForm" action="#script_name#" method="post">
		<cfinput type="hidden" name="view" value="#view#">

		<div class="buttonBar">
			<table cellpadding="0" cellspacing="0" border="0" width="100%">
				<tr>
					<td>
						<a href="#script_name#?view=createPayment&rv=#view#&paymentID=0&scholarshipID=0" class="formLink">New&nbsp;payment</a>
						<!--- <a href="" onclick="alert('E\-mail selected feature is not available'); return false; emailSelected(); return false;" class="formLink">E-mail selected</a> --->
						<a href="/applications/admin/methods/export.cfm?view=#view#" target="_blank" class="formLink">Export</a>
					</td>
					<td align="right">
						<strong>Count:</strong> #payments.RecordCount#
					</td>
				</tr>
			</table>
		</div>

		<!--- filter --->
		<script type="text/javascript" language="javascript">
		<!--
			toggleVisibility = function(objId) {
				var obj = document.getElementById(objId);
				if (obj.style.visibility == "visible") {
					obj.style.visibility = "hidden";
					obj.style.display = "none";
				} else {
					obj.style.visibility = "visible";
					obj.style.display = "block";
				}
			}

			updateFilterLink = function() {
				if (document.getElementById("filterSelections").style.visibility == "visible") {
					document.getElementById("filterLink").innerHTML = '#minusImage#&nbsp;Hide Filter';
				} else {
					document.getElementById("filterLink").innerHTML = '#plusImage#&nbsp;Show Filter';
				}
			}

			updateIDsSelect = function(selectObj) {
				if (selectObj.selectedIndex == 0) {
					selectObj.selectedIndex = 0;
				}
			}
		// -->
		</script>

		<cfset scholarshipTypes = application.scholarshipGateway.getScholarshipTypes()>
		<cfset terms = application.paymentScheduleGateway.getTerms()>

		<table class="filter" width="100%">
			<tr>
				<td class="filterHeader"><a id="filterLink"href="" onclick="toggleVisibility('filterSelections'); toggleVisibility('filterButtons'); updateFilterLink(); return false;" style="width: 100px; display: inline-block;">#plusImage#&nbsp;Show Filter</a><cfif filtered>List is filtered</cfif></td>
			</tr>
			<tr id="filterSelections" style="visibility: hidden; display: none;">
				<td>

					<table>
						<tr>
							<td>
								<fieldset>
									<legend>Cohort</legend>
									<input type="radio" id="cohort1" name="filterCohorts" value="All"<cfif filterCohorts eq "All"> checked="true"</cfif>><label for="cohort1">&nbsp;All</label><br>
									<input type="radio" id="cohort2" name="filterCohorts" value="1"<cfif filterCohorts eq "1"> checked="true"</cfif>><label for="cohort2">&nbsp;1</label><br>
									<input type="radio" id="cohort3" name="filterCohorts" value="2"<cfif filterCohorts eq "2"> checked="true"</cfif>><label for="cohort3">&nbsp;2</label><br />
									<input type="radio" id="cohort4" name="filterCohorts" value="3"<cfif filterCohorts eq "3"> checked="true"</cfif>><label for="cohort4">&nbsp;3</label>
									<input type="radio" id="cohort5" name="filterCohorts" value="4"<cfif filterCohorts eq "4"> checked="true"</cfif>><label for="cohort5">&nbsp;4</label>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>Scholarship Types</legend>
									<cfselect name="filterTypes" size="7" multiple="true" required="yes" message="Scholarship Types is required" onChange="updateIDsSelect(this);">
										<option value="All"<cfif filterTypes eq "All"> selected</cfif>>All</option>
										<cfloop query="scholarshipTypes">
											<option value="#Scholarship_Type#"<cfif ListFind(filterTypes, Scholarship_Type)> selected</cfif>>#Scholarship_Type#</option>
										</cfloop>
									</cfselect>
									<div class="footnote">Ctrl to multi-select</div>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>Terms</legend>
									<cfselect name="filterTerms" size="7" multiple="true" required="yes" message="Terms is required" onChange="updateIDsSelect(this);">
										<option value="All"<cfif filterTerms eq "All"> selected</cfif>>All</option>
										<option value="Fall 2009"<cfif ListFind(filterTerms, "Fall 2009")> selected</cfif>>Fall 2009</option>
										<option value="Spring 2010"<cfif ListFind(filterTerms, "Spring 2010")> selected</cfif>>Spring 2010</option>
										<option value="Winter 2010"<cfif ListFind(filterTerms, "Winter 2010")> selected</cfif>>Winter 2010</option>
										<option value="Fall 2010"<cfif ListFind(filterTerms, "Fall 2010")> selected</cfif>>Fall 2010</option>
										<option value="Spring 2011"<cfif ListFind(filterTerms, "Spring 2011")> selected</cfif>>Spring 2011</option>
										<option value="Winter 2011"<cfif ListFind(filterTerms, "Winter 2011")> selected</cfif>>Winter 2011</option>
										<option value="Fall 2011"<cfif ListFind(filterTerms, "Fall 2011")> selected</cfif>>Fall 2011</option>
										<option value="Spring 2012"<cfif ListFind(filterTerms, "Spring 2012")> selected</cfif>>Spring 2012</option>
										<option value="Winter 2012"<cfif ListFind(filterTerms, "Winter 2012")> selected</cfif>>Winter 2012</option>
									</cfselect>
									<div class="footnote">Ctrl to multi-select</div>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>Term Type</legend>
									<input type="radio" id="termType1" name="filterTermTypes" value="All"<cfif filterTermTypes eq "All"> checked="true"</cfif>><label for="termType1">&nbsp;All</label><br>
									<input type="radio" id="termType2" name="filterTermTypes" value="Semester"<cfif filterTermTypes eq "Semester"> checked="true"</cfif>><label for="termType2">&nbsp;Semester</label><br>
									<input type="radio" id="termType3" name="filterTermTypes" value="Quarter"<cfif filterTermTypes eq "Quarter"> checked="true"</cfif>><label for="termType3">&nbsp;Quarter</label>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>Verification Type</legend>
									<input type="radio" id="verificationTypes1" name="filterVerificationTypes" value="All"<cfif filterVerificationTypes eq "All"> checked="true"</cfif>><label for="verificationTypes1">&nbsp;All</label><br>
									<input type="radio" id="verificationTypes2" name="filterVerificationTypes" value="Enrollment"<cfif filterVerificationTypes eq "Enrollment"> checked="true"</cfif>><label for="verificationTypes2">&nbsp;Enrollment</label><br>
									<input type="radio" id="verificationTypes3" name="filterVerificationTypes" value="Performance"<cfif filterVerificationTypes eq "Performance"> checked="true"</cfif>><label for="verificationTypes3">&nbsp;Performance</label>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>Has Payment</legend>
									<input type="radio" id="optOut1" name="filterOptOuts" value="All"<cfif filterOptOuts eq "All"> checked="true"</cfif>><label for="optOut1">&nbsp;All</label><br>
									<input type="radio" id="optOut2" name="filterOptOuts" value="0"<cfif filterOptOuts eq "No"> checked="true"</cfif>><label for="optOut2">&nbsp;Yes</label><br>
									<input type="radio" id="optOut3" name="filterOptOuts" value="1"<cfif filterOptOuts eq "Yes"> checked="true"</cfif>><label for="optOut3">&nbsp;No</label>
								</fieldset>
							</td>
							<td>
								<fieldset>
									<legend>CAFC Auth</legend>
									<input type="radio" id="authorized1" name="filterAuthorized" value="All"<cfif filterAuthorized eq "All"> checked="true"</cfif>><label for="authorized1">&nbsp;All</label><br>
									<input type="radio" id="authorized2" name="filterAuthorized" value="1"<cfif filterAuthorized eq "Yes"> checked="true"</cfif>><label for="authorized2">&nbsp;Yes</label><br>
									<input type="radio" id="authorized3" name="filterAuthorized" value="0"<cfif filterAuthorized eq "No"> checked="true"</cfif>><label for="authorized3">&nbsp;No</label>
								</fieldset>
							</td>
							<cfinput type="hidden" name="filterPaymentTypes" value="All">
							<!---<cfinput type="hidden" name="filterOptOuts" value="All">--->
							<td>
								<fieldset>
									<legend>Keywords</legend>
									<cfinput type="text" name="filterSearchCriteria" value="#filterSearchCriteria#" size="20">
								</fieldset>
							</td>
							<td width="100%"></td>
						</tr>
					</table>

				</td>
			</tr>
			<tr id="filterButtons" style="visibility: hidden; display: none;">
				<td>
					<div style="margin-bottom: 4px;">
						<cfinput type="submit" name="applyFilterButton" id="applyFilterButton" value="Apply Filter" class="formButton2">
						<cfif filtered>
							<a href="#script_name#?view=#view#&filterCohorts=All&filterTypes=All&filterTerms=All&filterVerificationTypes=All&filterTermTypes=All&filterOptOuts=All&filterPaymentTypes=All&filterSearchCriteria=" class="formLink2">Clear filter</a>
						</cfif>
					</div>
				</td>
			</tr>
		</table>

		<cfif payments.RecordCount gt 0>

			<!--- checkbox functions --->
			<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
				<script type="text/javascript" language="javascript">
				<!--
					toggleSelectAll = function(f) {
						var c = f.selectAllCheckbox;
						for (var i=0; i<f.paymentIDs.length; i++) {
							if (c.checked) {
								f.paymentIDs[i].checked = true;
							} else {
								f.paymentIDs[i].checked = false;
							}
						}
					}

					updateSelectAll = function(chk) {
						if (!chk) {
							document.getElementById("selectAllCheckbox").checked = false;
						}
					}

					emailSelected = function() {
						var f = document.getElementById("paymentsForm");
						var paymentIDs = new Array();
						for (var i=0; i<f.paymentIDs.length; i++) {
							if (f.paymentIDs[i].checked) {
								paymentIDs[paymentIDs.length] = f.paymentIDs[i].value;
							}
						}
						if (paymentIDs.length == 0) {
							alert("Select at least one payment");
						} else {
							eSF = document.getElementById("emailSelectedForm");
							eSF.paymentIDs.value = paymentIDs;
							eSF.submit();
						}
					}
				// -->
				</script>
			</cfif>

			<table class="list" width="100%">
				<tr>
					<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
						<th><input name="selectAllCheckbox" id="selectAllCheckbox" type="checkbox" onclick="toggleSelectAll(this.form);"></th>
					</cfif>
					<th><a href="#script_name#?view=#view#&orderBy=Payment_ID<cfif orderBy eq 'Payment_ID' and orderDir eq 'asc'>&orderDir=desc</cfif>">ID<cfif orderBy eq "Payment_ID">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Scholarship.Cohort<cfif orderBy eq 'Scholarship.Cohort' and orderDir eq 'asc'>&orderDir=desc</cfif>">Cohort<cfif orderBy eq "Scholarship.Cohort">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Scholarship.Scholarship_Type<cfif orderBy eq 'Scholarship.Scholarship_Type' and orderDir eq 'asc'>&orderDir=desc</cfif>">Scholarship Type<cfif orderBy eq "Scholarship.Scholarship_Type">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment_Schedule.Term<cfif orderBy eq 'Payment_Schedule.Term' and orderDir eq 'asc'>&orderDir=desc</cfif>">Term<cfif orderBy eq "Payment_Schedule.Term">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment_Schedule.Term_Type<cfif orderBy eq 'Payment_Schedule.Term_Type' and orderDir eq 'asc'>&orderDir=desc</cfif>">Term Type<cfif orderBy eq "Payment_Schedule.Term_Type">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment_Schedule.Verification_Type<cfif orderBy eq 'Payment_Schedule.Verification_Type' and orderDir eq 'asc'>&orderDir=desc</cfif>">Verification Type<cfif orderBy eq "Payment_Schedule.Verification_Type">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Claim_ID<cfif orderBy eq 'Claim_ID' and orderDir eq 'asc'>&orderDir=desc</cfif>">Claim ID<cfif orderBy eq "Claim_ID">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Scholarship.Last_Name<cfif orderBy eq 'Scholarship.Last_Name' and orderDir eq 'asc'>&orderDir=desc</cfif>">Name<cfif orderBy eq "Scholarship.Last_Name">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment.Approval_Date<cfif orderBy eq 'Payment.Approval_Date' and orderDir eq 'asc'>&orderDir=desc</cfif>">Approval Date<cfif orderBy eq "Payment.Approval_Date">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment.Payment_Date<cfif orderBy eq 'Payment.Payment_Date' and orderDir eq 'asc'>&orderDir=desc</cfif>">Payment Date<cfif orderBy eq "Payment.Payment_Date">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment.Payment_Reference<cfif orderBy eq 'Payment.Payment_Reference' and orderDir eq 'asc'>&orderDir=desc</cfif>">Payment Reference<cfif orderBy eq "Payment.Payment_Reference">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
					<th><a href="#script_name#?view=#view#&orderBy=Payment.Payment_Amount<cfif orderBy eq 'Payment.Payment_Amount' and orderDir eq 'asc'>&orderDir=desc</cfif>">Amount<cfif orderBy eq "Payment.Payment_Amount">&nbsp;&nbsp;<cfif orderDir eq "asc">#ascImage#<cfelse>#descImage#</cfif></cfif></a></th>
				</tr>
				<cfloop query="payments">
					<tr<cfif currentRow mod 2 eq 0> class="evenRow"<cfelse> class="oddRow"</cfif>>
						<cfif IsUserInRole("Super User") or IsUserInRole("Regional Admin")>
							<td><input type="checkbox" name="paymentIDs" value="#Scholarship_ID#" onclick="updateSelectAll(this.checked);"<cfif ListFind(paymentIDs, Scholarship_ID)> checked</cfif>></td>
						</cfif>
						<td><a href="#script_name#?view=editPayment&rv=#view#&scholarshipID=#Scholarship_ID#&paymentID=#Payment_ID#">#Payment_ID#</a></td>
						<!--- <td>#Payment_ID#</td> --->
						<td>#Cohort#</td>
						<td>#Scholarship_Type#</td>
						<td>#Term#</td>
						<td>#Term_Type#</td>
						<td>#Verification_Type#</td>
						<td>#Claim_ID#</td>
						<td>#scholarshipFirstName# #scholarshipLastName#</td>
						<td>#DateFormat(Approval_Date, "m/d/yyy")#</td>
						<td>#DateFormat(Payment_Date, "m/d/yyy")#</td>
						<td>#Payment_Reference#</td>
						<td align="right">
							<cfif IsNumeric(paymentAmount)>
								$#NumberFormat(paymentAmount)#
							<cfelseif Opt_Out eq 1>
								No Payment
							</cfif>
						</td>
					</tr>
				</cfloop>
			</table>
		</cfif>
	</cfform>

	<cfif payments.RecordCount eq 0>

		<div class="alert alert-info notFound">No payments with the selected filter criteria</div>

		<!--- show filter --->
		<script type="text/javascript" language="javascript">
		<!--
			toggleVisibility('filterSelections');
			toggleVisibility('filterButtons');
			updateFilterLink();
		// -->
		</script>

	</cfif>

</cfoutput>


</body>
</html>